import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import postcss from 'postcss-pxtorem'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vite.dev/config/
export default defineConfig({
  // 适配移动端
  css: {
    postcss: {
      plugins: [
        postcss({
          rootValue({ file }) {
            return file.indexOf('vant')  ? 37.5 : 75
          },
          propList: ['*'],
          selectorBlackList: [],
          minPixeLValue: 2,
        }),
      ],
    },
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    port: 8080,
    proxy: {
      '/health': {
        target: 'http://172.27.6.139/api',
        changeOrigin: true,

        // rewrite: (path) => path.replace('/health', '')

      },

            '/api': {
        target: 'http://localhost:3000/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },

      // '/api':{
      //   target: 'http://172.17.8.100',
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace('/api', '')
      // }
    },
  },
})
